// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   KJVFormatter.java

package presenter;

import java.io.*;
import java.util.ArrayList;
import javax.swing.JFileChooser;

public class KJVFormatter
{

    public KJVFormatter(String bible)
    {
        int book = 1;
        int chapter = 1;
        int verse = 1;
        String line = "";
        String nextVerse = "";
        String nextChapterLine = "";
        try
        {
            ArrayList<String> formatted = new ArrayList<String>();
            BufferedReader br = new BufferedReader(new FileReader(bible));
            do
            {
                line = "";
                nextVerse = "";
                nextChapterLine = "";
                String nextBook = "";
                if(book < 10)
                    line = (new StringBuilder()).append(line).append("0").toString();
                line = (new StringBuilder()).append(line).append(book).toString();
                line = (new StringBuilder()).append(line).append(":").toString();
                if(chapter < 100)
                    line = (new StringBuilder()).append(line).append("0").toString();
                if(chapter < 10)
                    line = (new StringBuilder()).append(line).append("0").toString();
                line = (new StringBuilder()).append(line).append(chapter).toString();
                line = (new StringBuilder()).append(line).append(":").toString();
                if(verse < 100)
                    line = (new StringBuilder()).append(line).append("0").toString();
                if(verse < 10)
                    line = (new StringBuilder()).append(line).append("0").toString();
                line = (new StringBuilder()).append(line).append(verse).toString();
                if(book < 10)
                    nextVerse = (new StringBuilder()).append(nextVerse).append("0").toString();
                nextVerse = (new StringBuilder()).append(nextVerse).append(book).toString();
                nextVerse = (new StringBuilder()).append(nextVerse).append(":").toString();
                if(chapter < 100)
                    nextVerse = (new StringBuilder()).append(nextVerse).append("0").toString();
                if(chapter < 10)
                    nextVerse = (new StringBuilder()).append(nextVerse).append("0").toString();
                nextVerse = (new StringBuilder()).append(nextVerse).append(chapter).toString();
                nextVerse = (new StringBuilder()).append(nextVerse).append(":").toString();
                if(verse < 100)
                    nextVerse = (new StringBuilder()).append(nextVerse).append("0").toString();
                if(verse < 10)
                    nextVerse = (new StringBuilder()).append(nextVerse).append("0").toString();
                nextVerse = (new StringBuilder()).append(nextVerse).append(verse + 1).toString();
                if(book < 10)
                    nextChapterLine = (new StringBuilder()).append(nextChapterLine).append("0").toString();
                nextChapterLine = (new StringBuilder()).append(nextChapterLine).append(book).toString();
                nextChapterLine = (new StringBuilder()).append(nextChapterLine).append(":").toString();
                if(chapter < 99)
                    nextChapterLine = (new StringBuilder()).append(nextChapterLine).append("0").toString();
                if(chapter < 9)
                    nextChapterLine = (new StringBuilder()).append(nextChapterLine).append("0").toString();
                nextChapterLine = (new StringBuilder()).append(nextChapterLine).append(chapter + 1).toString();
                nextChapterLine = (new StringBuilder()).append(nextChapterLine).append(":").toString();
                nextChapterLine = (new StringBuilder()).append(nextChapterLine).append("001").toString();
                if(book < 9)
                    nextBook = (new StringBuilder()).append(nextBook).append("0").toString();
                nextBook = (new StringBuilder()).append(nextBook).append(book + 1).toString();
                nextBook = (new StringBuilder()).append(nextBook).append(":001:001").toString();
                String current = br.readLine();
                if(current == null)
                    break;
                if(current.contains("100"))
                    if(current.startsWith(line))
                    {
                        String front = (new StringBuilder()).append(chapter).append(":").append(verse).toString();
                        String back = current.substring(line.length());
                        formatted.add((new StringBuilder()).append(front).append(back).toString());
                        verse++;
                    } else
                    if(current.startsWith(nextVerse))
                    {
                        String front = (new StringBuilder()).append(chapter).append(":").append(verse + 1).toString();
                        String back = current.substring(nextVerse.length());
                        formatted.add((new StringBuilder()).append(front).append(back).toString());
                        verse += 2;
                    } else
                    if(current.startsWith(nextChapterLine))
                    {
                        String front = (new StringBuilder()).append(chapter + 1).append(":1").toString();
                        String back = current.substring(nextChapterLine.length());
                        formatted.add((new StringBuilder()).append(front).append(back).toString());
                        chapter++;
                        verse = 1;
                    } else
                    if(current.startsWith(nextBook))
                    {
                        String front = "1:1";
                        String back = current.substring(nextBook.length());
                        formatted.add((new StringBuilder()).append(front).append(back).toString());
                        book++;
                        chapter = 1;
                        verse = 1;
                    } else
                    {
                        formatted.add(current);
                    }
                if(current.contains(nextVerse) && !current.startsWith(nextVerse))
                {
                    String front = current.substring(0, current.indexOf(nextVerse));
                    String back = current.substring(current.indexOf(nextVerse), current.length());
                    formatted.add(front);
                    formatted.add(" ");
                    formatted.add(back);
                    verse++;
                }
            } while(true);
            JFileChooser jfc = new JFileChooser(bible);
            int x = jfc.showSaveDialog(null);
            if(x == 0)
            {
                BufferedWriter bw = new BufferedWriter(new FileWriter(jfc.getSelectedFile()));
                for(int i = 0; i < formatted.size(); i++)
                {
                    bw.write((String)formatted.get(i));
                    bw.newLine();
                }

                bw.close();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void main(String args[])
    {
        new KJVFormatter("Bibles/King James Version.txt");
    }
}
